import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // 登录
  {
    path: '/',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  // 主页
  {
    path: '/index',
    name: 'index',
    component: () => import('@/layouts/default.vue'),
    children: [
      /* 首页 */
      {
        path: '/mainpage',
        name: 'mainpage',
        component: () => import('@/views/mainpage/sy/index.vue'),
        meta: {
          name: '能力大厅',
          level: 1
        }
      },
      // 能力管理
      {
        path: '/nlgl',
        name: 'nlgl',
        redirect: "/nlgl/wdfb",
        component: () => import('@/views/nlgl/index.vue'),
        children: [
          // 我的发布
          {
            path: '/nlgl/wdfb',
            name: 'wdfb',
            component: () => import('@/views/grzx/wdfb/index.vue'),
            meta: {
              name: '我的发布',
              level: 2
            }
          },
          // 服务编排
          {
            path: '/nlgl/fwlcbp',
            name: 'fwlcbp',
            component: () => import('@/views/grzx/fwlcbpsy/index.vue'),
            meta: {
              name: '服务编排',
              level: 2
            }
          },
          // 认证鉴权
          {
            path: '/nlgl/aqrz',
            name: 'aqrz',
            component: () => import('@/views/grzx/aqrz/index.vue'),
            meta: {
              name: '认证鉴权',
              level: 2
            }
          },
          // 管理员首页
          {
            path: '/nlgl/adminMainpage',
            name: 'adminMainpage',
            component: () => import('@/views/admin-mainpage/index.vue'),
            meta: {
              name: '能力分类',
              level: 2
            }
          },
        ],
        meta: {
          name: '能力管理',
          level: 1
        },
      },
      // 能力看板
      {
        path: '/nlkb',
        name: 'nlkb',
        component: () => import('@/views/mainpage/nlkb/index.vue'),
        meta: {
          name: '能力看板',
          level: 1
        }
      },
      // 能力详情
      {
        path: '/nlxq',
        name: 'nlxq',
        component: () => import('@/views/mainpage/nlxq/index.vue'),
        meta: {
          name: '能力详情',
          level: 'other'
        }
      },


      // 服务验证
      {
        path: '/zxts',
        name: 'zxts',
        component: () => import('@/views/mainpage/zxts/index.vue'),
        meta: {
          name: '服务验证',
          level: 'other'
        }
      },
      // 签名指南
      {
        path: '/signGuide',
        name: 'signGuide',
        meta: {
          name: '签名指南',
          level: 'other'
        },
        component: () => import('@/views/mainpage/zxts/signGuide.vue'),
      },

      // 测试验证
      {
        path: '/csts',
        name: 'csts',
        component: () => import('@/views/mainpage/csts/index.vue'),
        meta: {
          name: '测试验证',
          level: 'other'
        }
      },

      /* 个人中心 */
      {
        path: '/grzx',
        name: 'grzx',
        redirect: '/grzx/wdsq',
        component: () => import('@/views/grzx/index.vue'),
        children: [
          // 我的申请
          {
            path: '/grzx/wdsq',
            name: 'wdsq',
            component: () => import('@/views/grzx/wdsq/index.vue'),
            meta: {
              name: '我的申请',
              level: 2
            }
          },
          // 我的审批
          {
            path: '/grzx/wdqx',
            name: 'wdqx',
            component: () => import('@/views/grzx/wdqx/index.vue'),
            meta: {
              name: '我的审批',
              level: 2
            }
          },
          // 服务订阅
          {
            path: '/grzx/fwdy',
            name: 'fwdy',
            component: () => import('@/views/grzx/fwdy/index.vue'),
            meta: {
              name: '服务订阅',
              level: 2
            }
          },
          // 常用工具箱
          {
            path: '/grzx/cygjx',
            name: 'cygjx',
            meta: {
              name: '常用工具箱',
              level: 2
            },
            component: () => import('@/views/grzx/cygjx/index.vue'),
          },
        ],
        meta: {
          name: '个人中心',
          level: 1
        },
      },

      // 新增申请
      {
        path: '/nlsq',
        name: 'nlsq',
        component: () => import('@/views/grzx/nlsq/index.vue'),
        meta: {
          name: '创建申请单',
          level: 'other'
        }
      },
      // 能力发布
      {
        path: '/nlfb',
        name: 'nlfb',
        component: () => import('@/views/grzx/nlfb/index.vue'),
        meta: {
          name: '能力发布',
          level: 'other'
        }
      },

      // 服务编排编辑页
      {
        path: '/fwbp',
        name: 'fwbp',
        component: () => import('@/views/grzx/fwbp/index.vue'),
        meta: {
          name: 'API服务编排',
          level: 'other'
        }
      },
      // 菜单权限
      {
        path: '/xtgl/cdqx',
        name: 'cdqx',
        meta: {
          name: '菜单权限',
          level: 1
        },
        component: () => import('@/components/Zzjg/Gnzj.vue')
      },
      // 用户权限
      {
        path: '/xtgl/yhqx',
        name: 'yhqx',
        meta: {
          name: '用户权限',
          level: 1
        },
        component: () => import('@/components/Zzjg/Yhqx.vue')
      },
      // 组织机构
      {
        path: '/xtgl/zzjg',
        name: 'yhqx',
        meta: {
          name: '组织机构',
          level: 1
        },
        component: () => import('@/components/Zzjg/Zzjg.vue')
      },
      // 操作日志
      {
        path: '/xtgl/czrz',
        name: 'czrz',
        meta: {
          name: '系统管理',
          level: 1
        },
        component: () => import('@/components/Zzjg/Rzcx.vue')
      },


    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   const vuex = JSON.parse(sessionStorage.getItem('vuex'))
//   // 不需要在请求返回后统一处理的URL
//   const EXCLUDE_URLS = ['/', '/404', '/demo']

//   if (EXCLUDE_URLS.indexOf(to.path) >= 0) {
//     next()
//   } else {
//     if (!vuex) next('/')
//     const gnList = vuex.personInfo.gnList
//     let flag = false
//     const recursion = arr => {
//       if (arr && arr.length > 0) {
//         arr.forEach(item => {
//           if (!flag && item.gndz === to.path) {
//             flag = true
//           } else {
//             recursion(item.children)
//           }
//         })
//       }
//     }
//     recursion(gnList, 'gndz')
//     if (flag) {
//       next()
//     } else {
//       next('/404')
//     }
//   }
// })

export default router
